package com.chinamobile.websocket.websocket.config;

import com.chinamobile.websocket.websocket.endpoint.WebSocketEndpointHandler;
import com.chinamobile.websocket.websocket.filter.WebsocketHandshakInteceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

/**
 * @className: WebSocketConfig
 * @description websocket配置
 * @author: fanzhijun
 * @date: 2024/1/18
 **/
@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(new WebSocketEndpointHandler(), "/commonWebsocket/{type}/{uniKey}/{token}")
                .addInterceptors(new WebsocketHandshakInteceptor())
                .setAllowedOrigins("*");
    }
}
